forum

Home / DeveloperSection / Forums / How to set a asp:DropDownList SelectedValue to a Session Variable?

How to set a asp:DropDownList SelectedValue to a Session Variable?

Tom Cruser 5382 21-Dec-2014

There are several articles describing how to do this is code behind however: 

Is it possible to set the value of a dropdownlist to a session variable on the aspx page? 

I am using SqlDataSource to populate the dropdownlist so do not wish to add code behind if it can be avoided. 

<asp:DropDownList ID="ddl" runat="Server" DataSourceID="sqlDS" DataValueField="ID" DataTextField="TEXT" AppendDataBoundItems="true">
  <asp:ListItem Text="" Value="" Selected="True" />
</asp:DropDownList> 
<asp:SqlDataSource ID="sqlDS" runat="Server" SelectCommand="spDS" SelectCommandType="StoredProcedure" />

Set Session("ID") as selected value on load? 

The dropdown list is already populated from the sqldatasource. I just want to set the initial value on page load.


Updated on 22-Dec-2014

Can you answer this question?


Answer

2 Answers

Liked By